Momentum: MACD Spread¶


2023-02-21.

Summary¶

We test a systematic strategy based on a spread variation of the Moving Average Convergence / Divergence (MACD) indicators on a BTC/USD portfolio.

Hypothesis: Rebalancing portfolio on MACD spread on tiered overbought/oversold signals performs better on a risk-adjusted basis than holding BTC over certain periods.

Parameters:

  • Date: 2011-02-10 to 2023-02-09
  • Frequency: daily
  • No additional buy in after Time 0
  • No trading fees
  • No shorting

Findings:

  • Overall, MACD spread portfolio results in lower annualized Sharpe Ratio generally (excl. rf, both simple and log returns) than holding
  • In few cases, portfolio outperforms holding in non-annualized and annualized Sharpe Ratio

Discussion -> Next Steps:

  • Strategy missed ~first half of 2017 bull run -> perhaps overtuned to avoid bear runs, alternatives: adjust tiers, buy cheap puts while holding
  • Need to backtest over training / testing data

1. Data¶


1.1. Import¶

Market Data as of: 2023-02-10
BTC price data: Coin Metrics 'ReferenceRateUSD'
SPY price data: WSJ Market Data

btc
time
2009-01-03 0.000000
2009-01-04 0.000000
2009-01-05 0.000000
2009-01-06 0.000000
2009-01-07 0.000000
... ...
2023-02-05 23355.524386
2023-02-06 22957.225191
2023-02-07 22745.165037
2023-02-08 23266.269204
2023-02-09 22937.579945

5151 rows × 1 columns

btc
count 5151.000000
mean 7756.203500
std 13940.029711
min 0.000000
25% 11.052683
50% 589.373502
75% 8795.111442
max 67541.755508
Open High Low Close Volume
Date
2010-12-29 125.98 126.20 125.9000 125.92 58033039
2010-12-30 125.80 126.13 125.5300 125.72 76616852
2010-12-31 125.53 125.87 125.3300 125.75 91270273
2011-01-03 126.71 127.60 125.6969 127.05 138725203
2011-01-04 127.33 127.37 126.1900 126.98 137409703
... ... ... ... ... ...
2023-02-03 411.59 416.97 411.0900 412.35 94736781
2023-02-06 409.79 411.29 408.1000 409.83 60295328
2023-02-07 408.87 416.49 407.5700 415.19 90990750
2023-02-08 413.13 414.53 409.9300 410.65 76227453
2023-02-09 414.41 414.57 405.8100 407.09 78694867

3050 rows × 5 columns

Open High Low Close Volume
count 3050.000000 3050.000000 3050.000000 3050.000000 3.050000e+03
mean 251.600702 253.000111 250.076330 251.637781 1.104180e+08
std 95.916431 96.577802 95.175804 95.917162 6.411999e+07
min 108.350000 112.580000 107.430000 109.930000 2.027001e+07
25% 181.357500 182.102250 180.807500 181.591250 6.824341e+07
50% 226.875000 227.780000 226.140000 227.075000 9.334451e+07
75% 303.460000 306.201250 300.665000 303.322500 1.340440e+08
max 479.220000 479.980000 476.060000 477.710000 7.178286e+08

1.2. Analysis¶

We observe that BTC historical price movement is exponential relative to the SPY as benchmark. Logging BTC price is warranted for strategies.

BTC's 1yr trailing correlation with SPY is around 0.15. It is higher under 90d trailing and 30d trailing, reaching at peaks around 0.38 and 0.6 historically.

Further, we see from the histogram and more clearly QQ plot that historical BTC returns distribution is far less normally distributed compared to SPY with long tail returns.

High volatility and exponential price movement make moving averages, and momentum strategies in general, less applicable to BTC due to their reliance on smoothing over historical trailing periods. Further, annualizing Sharpe ratio from daily returns is less applicable due to particularly evident violation of IID. Preliminary analysis suggests momentum might not outperform holding, and that exponential moving averaging should outperform simple moving averaging.

2. Create Signals¶


2.1. Define Variables¶

The standard MACD Logic is as follows:

  • MACD line = 12d price EMA - 26d price EMA
  • Signal line = 9d MACD EMA
  • Long: MACD line - Signal line > 0 (cross over)
  • Short/sell: MACD line - signal line < 0 (cross under)

We make the following adjustments:

  • Use SMA instead of EMA
  • MACD spread = 26d overbought/oversold SMA z scores
  • Long: MACD spread < z score threshold (oversold) based on tiers
  • Sell: MACD spread > z score threshold (overbought) based on tiers
  • When overbought, do not buy until oversold (see tier table below)
  • At Time = 0, hold Portfolio at 100% USD until oversold then buy into BTC accordingly
Z score example Min Max BTC USD
Extreme Overbought 3 N/A 0.05 0.95
Overbought 2 3 0.2 0.8
Slight Overbought 1 2 0.35 0.65
Neutral -1 1 0.5 0.5
Slight Oversold -2 -1 0.65 0.35
Oversold -3 -2 0.8 0.2
Extreme Oversold N/A -3 0.95 0.05

2.2. Analysis¶

First we observe from the '26dma MACD spread btc' plot that MACD SMA spread is less volatile than BTC spread over the same period, resulting in less portfolio rebalancing. This is expected given MACD spread applies smoothing to BTC price three times: in creating MACD line (12dma - 26dma), in creating the signal line (9dma MACD line), and finally in the 26dma spread of the MACD/Signal difference. The result is likely lower risk than holding BTC.

Second we see that the MACD spread visibly diverges from the BTC spread. Although lower risk, the risk-adjusted returns might underperform if the portfolio returns fail to make up the difference.

3. Run Strategy¶


3.1. Portfolio Rebalancing¶

The rebalancing is calculated as follows: the signal at the end of previous day informs next day's portfolio distribution. For example, hypothetically at the end of 01-31-2021, we have a Z score of -2.5. The portfolio distributes 80% of current value to BTC, 20% to USD. On 02-01-2021, 80% of portfolio value from 01-31-2021 is subjected to 02-01-2021's BTC return for the day.

Calculations:
$V_T$ = portfolio value at time T
$P_T$ = proportion of BTC in the portfolio
$R_T$ = BTC daily simple returns

$$V_T = V_{T-1} * P_{T-1} * R_T$$

3.2. Analysis¶

The strategy sells BTC to 5% during three major periods and holds it in 0.05/0.95 BTC/USD ratio:

  1. 2011-Nov to 2012-Jan
  2. 2016-Jun to 2017-Jul
  3. 2020-Sep to 2020-Dec

During those periods, the graph shows the strategy could not take advantage of bull runs, in the particular the 2017 exponential bull run when price quadripled.

4. Performance Summary¶


4.1 Calculate Performance¶

We calculate the annualized Sharpe, Sortino, and Information ratio as follows:

$$Sharpe =\sqrt365 \ * \frac{\bar{R_p} - R_f}{\sigma_p}$$$$Sortino = \sqrt365 \ * \frac{\bar{R_p} - R_f}{\sigma_{downside \ risk}}$$$$Information = \sqrt365 \ * \frac{\bar{R_p} - \bar{R_h}}{\sigma_{tracking \ error}}$$

Where:

$$\bar{R_p} = mean(ln(\frac{R_{p,n}}{R_{p,n-1}}))$$$$\sigma_p = std(ln(\frac{R_{p,n}}{R_{p,n-1}}))$$$$\sigma_{downside \ risk} = std(ln(\frac{R_{p,n}}{R_{p,n-1}} < 0))$$$$\sigma_{tracking \ error} = std(ln(\frac{R_{p,n}}{R_{p,n-1}} - ln(\frac{R_{h,n}}{R_{h,n-1}}))$$

We use log returns instead of simple returns due averaging returns over multiple periods. Simple returns would have returned inflated ratios. We multiply by square root of 365 given our average mean returns is calculated on a daily basis, and BTC trades 24/7/.

4.2. Analysis¶

On an annualized basis, MACD SMA spread fails to outperform holding BTC in a risk-adjusted basis for all performance ratios across 1mo, 3mo, 6mo, 12mo, 24mo, and 36mo trailing periods. We see from the trailing returns and volatility plots that despite the portfolio halving volatility, it missed significant periods of high returns, which was likely a culprit for its underperformance.

This analysis is weak evidence against our hypothesis that MACD spreads beats holding BTC. Several factors mentioned at the start contributed to this performance, such as using SMA instead of EMA, and the difficulty of annualizing ratios. In fact, for the past 365 days, although MACD underperformed BTC, the actual results are:

  • MACD ret: -34%
  • BTC ret: -48%
  • MACD vol: 0.02
  • BTC vol: 0.04

On this non-annualized basis, MACD portfolio outperforms holding BTC. Next steps could be to give alternative performance indicators to capture these results.

Define Performance Table¶
Define Sharpe Ratio Plots¶
Define Sortino Ratio Plots¶
Define Information Ratio Plots¶
Draw Plots¶